import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zyj
 * @date 2022年06月09日 16:27
 */
public class 打印顺序是ABCABC {
    public static void main(String[] args) {
        ReentrantLock obj = new ReentrantLock(true);
        Condition condition = obj.newCondition();
        Thread a = new MyThread(obj,condition,"A");
        Thread b = new MyThread(obj,condition,"B");
        Thread c = new MyThread(obj,condition,"C");
        a.setPriority(10);
        b.setPriority(5);
        c.setPriority(1);
        a.start();
        b.start();
        c.start();
    }
}

class MyThread extends Thread{
    private ReentrantLock reentrantLock;
    private Condition condition;
    public MyThread(ReentrantLock reentrantLock,Condition condition,String name){
        super(name);
        this.reentrantLock = reentrantLock;
        this.condition = condition;
    }
    @Override
    public void run() {
            reentrantLock.lock();
            for (int i = 0;i < 5;i++){
                System.out.println(Thread.currentThread().getName());

               condition.signalAll();

                try {
                    condition.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            condition.signalAll();
            reentrantLock.unlock();


    }
}